﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Halcon二次开发.Model.帮助类.VHelper
{
    public enum MouseEventName { 
        MouseDown, 
        MouseMove, 
        MouseUp,
        MouseDoubleClick
    }
    public class MouseEventHelper
    {
        /// <summary>
        /// 给对应按钮注册事件
        /// </summary>
        public static void RegistryMouseEvent(Control control,MouseEventHandler del,
            MouseEventName eventName)
        {
            if (control.Controls.Count > 0) {

                foreach (Control item in control.Controls)
                {
                    switch (eventName) { 
                        case MouseEventName.MouseDown:
                            item.MouseDown += del;
                            break;
                        case MouseEventName.MouseMove:
                            item.MouseMove += del;
                            break;
                        case MouseEventName.MouseUp:
                            item.MouseUp += del;
                            break;
                        case MouseEventName.MouseDoubleClick:
                            item.MouseDoubleClick += del;
                            break;
                    }
                    //递归,确保都绑定上去事件
                    RegistryMouseEvent(item, del, eventName);
                }
            }
        }
    }
}
